<template>
	 <mdp-table showCheckbox subOpType="select" operWidth="100px" pageLayout="total" ref="tableListRef" :columnCfgs="columnCfgs" :crudApis="crudApis" @select="(d)=>$emit('select',d)" :preQueryCheck="preQueryCheck">
			<template #query="{page}"> 
				<ContentWrap :hideHeader="currOpType=='select'">
					<template #header>
						<el-space>
							<el-button icon="Plus" @click="page.batchDel">新增表</el-button> 
							<el-button icon="Delete" @click="page.batchDel">删除表</el-button> 
						</el-space> 
					</template>
					<el-space>
						<mdp-select-data-source v-model="page.filters.dataSource" width="100px" @change="($event)=>{dataSource=$event;$emit('dataSourceChange',$event)}"/>
						<el-input v-model="page.filters.tableName" clearable/>   
						<el-button @click="doSearch" type="primary">查询</el-button>
				</el-space>
			</ContentWrap>
			</template>
			<template #operColumn>
				<el-table-column label="操作" :width="120" fixed="right">   
					<template #default="scope">
						<el-dropdown split-button @command="doOperCommand($event,scope.row)" @click="onMenuClick(scope.row)"> 
							{{fromTypeCpd=='meta'?'结构':'数据'}}
							<template #dropdown>
								<el-dropdown-menu>
									<el-dropdown-item v-if="fromTypeCpd=='meta'" command="toTableData">数据管理</el-dropdown-item>  
									<el-dropdown-item v-if="fromTypeCpd=='data'" command="toTableStruct">表结构</el-dropdown-item>   
									<el-dropdown-item command="toClearTableData">清空数据</el-dropdown-item>
									<el-dropdown-item command="toDropTable">删除表</el-dropdown-item>
									<el-dropdown-item command="toFormDesigne">表单设计</el-dropdown-item>
								</el-dropdown-menu>
							</template>
						</el-dropdown>
					</template>
					
          </el-table-column>   
			</template>
	 </mdp-table>
</template> 
<script>  
import {getTableList} from '@/api/mdp/dm/meta'
export default {
	name: 'TableList', 
	props: {  
		/**
		 * 打开类型，从表解构过来还是从数据模块过来
		 */
		fromType:{
			type: String,
			default: 'meta',//meta|data
		},
		subOpType:{
			type:String,
			default: 'mng'
		}
	},
	data(){
		return {  
			columnCfgs:[
				{label:'表编号',property:'tableName'},
				{label:'表描述',property:'tableRemarks'}
			],
			crudApis:{
				list:getTableList
			},
			dataSource:'master',
		}
	},
	computed: { 
		currOpType(){
			return this.subOpType
		},
		fromTypeCpd:{
			set(val){
				this.$emit('update:fromType',val)
			},
			get(){
				return this.fromType
			}
		}
	}, 
	methods:{ 
		preQueryCheck:function(page){
			if(!page.filters.dataSource){
				this.$message({message:'请选择数据源',type:'info'})
				return false;
			}else{
				return true;
			}
		},
		doSearch(){  
			this.$emit('select',{})
			this.$refs['tableListRef'].searchTableDatas();   
			
		},
		showTableEditForm(page){

		},
		onMenuClick(row){
			if(this.fromType=='meta'){
				this.$emit('select',row,'meta')
			}else{
				this.$emit('select',row,'meta')
			}
		},
		doOperCommand($event,row){
			if($event=='toTableStruct'){ 
				this.$emit('select',row,'meta') 
				this.$router.push({path:`/mdp/dm/meta/table/struct/${this.dataSource}/${row.tableName}`})
			}else if($event=='toTableData'){  
				this.$emit('select',row,'data') 
				this.$router.push({path:`/mdp/dm/data/list/${this.dataSource}/${row.tableName}`})
			}else if($event=='toFormDesigne'){
				this.$router.push({path:`/mdp/form/design/add`})
			}else{
				this.$message({message:"开源版不支持，请联系商务"})
			}
		}
	},
	mounted() { 
	}
}
</script>
